package com.sneakxy.mybase4j.generator;

import java.io.FileNotFoundException;
import java.util.List;

import com.sneakxy.mybase4j.generator.config.Dirs;
import com.sneakxy.mybase4j.generator.core.ClassDesigner;
import com.sneakxy.mybase4j.generator.core.ClassField;

/**
 * @author 潜行的青衣
 * @see
 */
public class GeneratorBuilder {
	
	private String tableName;
	
	private Dirs dirs;
	
	private List<ClassField> primaryKeys;
	
	private List<ClassField> otherFields;
	
	private String modelName;
	
	private ClassDesigner modelDesigner;
	
	private ClassDesigner repositoryDesigner;
	
	private ClassDesigner serviceInterfaceDesigner;
	
	private ClassDesigner serviceImplDesigner;
	
	private ClassDesigner providerInterfaceDesigner;
	
	private ClassDesigner providerImplDesigner;
	
	private boolean buildModel = true;
	
	private boolean buildRepository = true;
	
	private boolean buildServiceInterface = true;
	
	private boolean buildServiceImpl = true;
	
	private boolean buildProviderInterface = true;
	
	private boolean buildProviderImpl = true;

	public GeneratorBuilder(
			Dirs dirs, String tableName, String modelName, List<ClassField> primaryKeys, List<ClassField> otherFields,
			ClassDesigner modelDesigner, ClassDesigner repositoryDesigner, 
			ClassDesigner serviceInterfaceDesigner, ClassDesigner serviceImplDesigner,
			ClassDesigner providerInterfaceDesigner, ClassDesigner providerImplDesigner) {
		this.dirs = dirs;
		this.tableName = tableName;
		this.modelName = modelName;
		this.primaryKeys = primaryKeys;
		this.otherFields = otherFields;
		this.modelDesigner = modelDesigner;
		this.repositoryDesigner = repositoryDesigner;
		this.serviceInterfaceDesigner = serviceInterfaceDesigner;
		this.serviceImplDesigner = serviceImplDesigner;
		this.providerInterfaceDesigner = providerInterfaceDesigner;
		this.providerImplDesigner = providerImplDesigner;
	}
	
	protected void build() throws FileNotFoundException {
		if(this.isBuildModel()) {
			this.modelDesigner.buildClass(this.dirs.getModelOutDir());
		}
		if(this.isBuildRepository()) {
			this.repositoryDesigner.buildClass(this.dirs.getRepositoryOutDir());
		}
		if(this.isBuildServiceInterface()) {
			this.serviceInterfaceDesigner.buildClass(this.dirs.getServiceInterfaceOutDir());
		}
		if(this.isBuildServiceImpl()) {
			this.serviceImplDesigner.buildClass(this.dirs.getServiceImplOutDir());
		}
		if(this.isBuildProviderInterface()) {
			this.providerInterfaceDesigner.buildClass(this.dirs.getProviderInterfaceOutDir());
		}
		if(this.isBuildProviderImpl()) {
			this.providerImplDesigner.buildClass(this.dirs.getProviderImplOutDir());
		}
	}

	public Dirs getDirs() {
		return dirs;
	}

	public String getTableName() {
		return tableName;
	}

	public List<ClassField> getPrimaryKeys() {
		return primaryKeys;
	}

	public List<ClassField> getOtherFields() {
		return otherFields;
	}

	public String getModelName() {
		return modelName;
	}

	public ClassDesigner getModelDesigner() {
		return modelDesigner;
	}

	public ClassDesigner getRepositoryDesigner() {
		return repositoryDesigner;
	}

	public ClassDesigner getServiceInterfaceDesigner() {
		return serviceInterfaceDesigner;
	}

	public ClassDesigner getServiceImplDesigner() {
		return serviceImplDesigner;
	}

	public boolean isBuildModel() {
		return buildModel;
	}

	public void setBuildModel(boolean buildModel) {
		this.buildModel = buildModel;
	}

	public boolean isBuildRepository() {
		return buildRepository;
	}

	public void setBuildRepository(boolean buildRepository) {
		this.buildRepository = buildRepository;
	}

	public boolean isBuildServiceInterface() {
		return buildServiceInterface;
	}

	public void setBuildServiceInterface(boolean buildServiceInterface) {
		this.buildServiceInterface = buildServiceInterface;
	}

	public boolean isBuildServiceImpl() {
		return buildServiceImpl;
	}

	public boolean isBuildProviderInterface() {
		return buildProviderInterface;
	}

	public void setBuildProviderInterface(boolean buildProviderInterface) {
		this.buildProviderInterface = buildProviderInterface;
	}

	public boolean isBuildProviderImpl() {
		return buildProviderImpl;
	}

	public void setBuildProviderImpl(boolean buildProviderImpl) {
		this.buildProviderImpl = buildProviderImpl;
	}

	public ClassDesigner getProviderInterfaceDesigner() {
		return providerInterfaceDesigner;
	}

	public ClassDesigner getProviderImplDesigner() {
		return providerImplDesigner;
	}

	public void setBuildServiceImpl(boolean buildServiceImpl) {
		this.buildServiceImpl = buildServiceImpl;
	}

}
